<?php
	class xl_trang extends database
	{
		function LoadAll()
		{
			$sql = "Select * from trang ORDER BY (ngaytao) DESC";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		
		function Load_DV_TrangChu()
		{
			$sql = "Select *, t.ngaytao as ngaydang from trang t, danhmuc d where t.maloaitrang = d.madanhmuc ORDER BY (t.ngaytao) DESC";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		function Load_Top5DichVu()
		{
			$sql = "Select * from trang ORDER BY (ngaytao) DESC LIMIT 0 , 5";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;

		}
		function Load_Load_Top5DichVu_noibat()
		{
			$sql = "Select * from trang t where noibat= 1 order by t.ngaytao DESC";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		//Toan - ADD - START - 8/5/2012
		function Load_DichVuTheoMaLoaiTrang($maLoaiTrang)
		{
			$sql = "Select * from trang where maloaitrang= '".$maLoaiTrang."' ORDER BY (ngaytao) DESC";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		
		function Load_DichVuTheoMaLoaiTrang_Limit($maLoaiTrang,$start, $display)
		{
			$sql = "Select * from trang where maloaitrang= '".$maLoaiTrang."' ORDER BY (ngaytao) DESC LIMIT $start, $display";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		
		function Load_DichVu_Theo_MaDichVu_MaTrang($maDichVu, $maTrang)
		{
			$sql = "Select * from trang where matrang= '".$maTrang."' and maloaitrang = '".$maDichVu."'";
			$this->setQuery($sql);
			$arr = $this->loadOneRow();
			$this->disconnect(); 
			return $arr;
		}
		//Toan - ADD - END - 8/5/2012
		function Load_DichVuTheoMa($matrang)
		{
			$sql = "Select * from trang where matrang= '".$matrang."' and maloaitrang = '5'";
			$this->setQuery($sql);
			$arr = $this->loadOneRow();
			$this->disconnect(); 
			return $arr;
		}
		
		function Load_DichVuTheoTenTat($ten)
		{
			$sql = "Select * from trang where tentat= '".$ten."' and maloaitrang = '5'";
			$this->setQuery($sql);
			$arr = $this->loadOneRow();
			$this->disconnect(); 
			return $arr;
		}
		//Phuong - ADD - START - 21/5/2012
		function Load_Theo_Ten_Ma_Dich_Vu($ten, $maDichVu)
		{
			$sql = "Select * from trang where tentat= '".$ten."' and maloaitrang = '".$maDichVu."'";
			$this->setQuery($sql);
			$arr = $this->loadOneRow();
			$this->disconnect(); 
			return $arr;
		}
		//Phuong - ADD - END - 21/5/2012

		
		function Load_DichVu()
		{
			$sql = "Select * from trang where maloaitrang = '5'";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		
		//Toan - MOD START - 29/02/2012
		function capnhat($matrang, $maloaitrang, $tieude,$noidungthugon, $noidung, $tags, $manguoidung, $tentat, $motatags)
		{
			$sql = "UPDATE trang set maloaitrang ='".$maloaitrang."' , tentrang = '".$tieude."',noidungthugon = '".$noidungthugon."', noidung ='".$noidung."', tags ='".$tags."', manguoidung ='".$manguoidung."', tentat = '".$tentat."', mota = '".$motatags."' where matrang='".$matrang."'";
			$this->setQuery($sql);
			return $this->query(); 
			//return $sql;
		}
		
		function capnhat_hinhanh($matrang, $hinhanh)
		{
			$sql = "UPDATE trang set hinhanh ='".$hinhanh."' where matrang='".$matrang."'";
			$this->setQuery($sql);
			return $this->query(); 
			//return $sql;
		}
			//Toan - MOD START - 08/03/2012
		/*function them_dich_vu($tentrang, $noidung, $tags, $ngaytao, $manguoidung, $tentat)
		{
			$sql = "INSERT INTO trang (maloaitrang, tentrang, noidung, tags, ngaytao, manguoidung, tinhtrang, tentat) values('5', '".$tentrang."','".$noidung."','".$tags."','".$ngaytao."','".$manguoidung."','0', '".$tentat."')";	
			$this->setQuery($sql);
			return $this->query();
			//return $sql;
			
		}*/
		function them_dich_vu($madanhmuc, $tentrang, $noidung_thugon, $noidung, $tags, $ngaytao, $manguoidung, $tentat, $mota, $hinhanh)
		{
			$sql = "INSERT INTO trang (maloaitrang, tentrang, noidungthugon, noidung, tags, ngaytao, manguoidung, tinhtrang, tentat, mota, hinhanh, noibat) values('".$madanhmuc."', '".$tentrang."', '".$noidung_thugon."' ,'".$noidung."','".$tags."','".$ngaytao."','".$manguoidung."','0','".$tentat."','".$mota."','".$hinhanh."',0)";	
			
			$this->setQuery($sql);
			return $this->query();
			//return $sql;
			
		}
		
		function them_dich_vu_khong_hinh_anh($madanhmuc, $tentrang, $noidung_thugon, $noidung, $tags, $ngaytao, $manguoidung, $tentat, $mota)
		{
			$sql = "INSERT INTO trang (maloaitrang, tentrang, noidungthugon, noidung, tags, ngaytao, manguoidung, tinhtrang, tentat, mota, noibat) values('".$madanhmuc."', '".$tentrang."', '".$noidung_thugon."' ,'".$noidung."','".$tags."','".$ngaytao."','".$manguoidung."','0','".$tentat."','".$mota."', 0)";	
			
			$this->setQuery($sql);
			return $this->query();
			//return $sql;
			
		}
			//Toan - MOD END - 08/03/2012
		function xoa_dich_vu($matrang)
		{	$sql ="delete from trang where matrang = '".$matrang."'";
			$this->setQuery($sql);
			return $this->query();
		}
		//Toan - MOD END - 29/02/2012
		//Toan - ADD START - 01/03/2012
		function kt_ten_viet_tat($tentat)
		{
			$sql = "Select * from trang where tentat = '".$tentat."'";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;	
		}
		
		function kt_ten_viet_tat_theo_id($id, $tentat)
		{
			$sql = "Select * from trang where matrang = '".$id."' and tentat = '".$tentat."'";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;	
		}
		
		function kt_ten_viet_tat_trung_theo_id($id, $tentat)
		{
			$sql = "Select * from trang where matrang <> '".$id."' and tentat = '".$tentat."'";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;	
		}
		//Toan - ADD END - 01/03/2012	
			
		//Toan - ADD START - 13/05/2012	
		function Load_dichvu_noibat()
		{
			$sql = "Select * from trang t, danhmuc d where t.maloaitrang = d.madanhmuc and noibat= 1 order by t.ngaytao DESC";
			$this->setQuery($sql);
			$arr = $this->loadAllRow();
			$this->disconnect(); 
			return $arr;
		}
		
		
		
		function xoa_dichvu_noibat($matrang)
		{
			$sql = "UPDATE trang set noibat = 0 where matrang =".$matrang;
			$this->setQuery($sql);
			return $this->query(); 			
		}
		
		function them_dichvu_noibat($matrang)
		{
			$sql = "UPDATE trang set noibat = 1 where matrang =".$matrang;
			$this->setQuery($sql);
			return $this->query(); 			
		}
		//Toan - ADD END - 13/05/2012	
		
	}
?>